home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / src / novia_subboard.c < prev    next >
Text File  |  1999-12-06  |  45KB  |  1,562 lines

  1. #include <exec/types.h>
  2. #include <stdlib.h>
  3. #include <intuition/screens.h>
  4. #include <exec/lists.h>
  5. #include <exec/nodes.h>
  6. #include <pragma/exec_lib.h>
  7. #include <pragma/dos_lib.h>
  8. #include <novia/novia_UserList.h>
  9. #include <novia/novia_PortData.h>
  10. #include <novia/novia_config.h>
  11. #include <novia/novia_mail.h>
  12. #include <novia/novia_subboard.h>
  13. #include <novia/novia_types.h>
  14. #include <novia/novia_misc.h>
  15. #include <novia/novia_message.h>
  16. #include <exec/memory.h>
  17. #include <dos/stdio.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <time.h>
  22. #include <novia/novia_funcs.h>
  23.  
  24. void GoBase();
  25. void RepairBase();
  26. struct Item *GetItem_byIP(ULONG dirIP,ULONG itemIP,struct Item *item,ULONG size);
  27. struct Subboard *GetSubboard_byIP(ULONG serialIP,struct Subboard *subboard,ULONG size);
  28.  
  29. struct MyNode {
  30.     struct MyNode     *ln_Succ;
  31.     struct MyNode    *ln_Pred;
  32.     UBYTE            ln_Type;
  33.     BYTE            ln_Pri;
  34.     BYTE             *ln_Name;
  35.     ULONG            IPNumber;
  36. };
  37.  
  38.  
  39. void GoBase()
  40. {
  41.     struct PortData *cport=(PortData *)FindTask(NULL)->tc_UserData;
  42.     char file_index[]=".index";
  43.     char file_data[]=".data";
  44.     char buffer[256],Quit=FALSE,Quit2=FALSE,habschon;
  45.     char root[70];
  46.     char path[256];
  47.     char odir[256];
  48.     List dirlist;
  49.     char nostdcmd;
  50.     long cmdid=0;
  51.     ULONG start;
  52.     ULONG end;
  53.     ULONG entrys=0;
  54.     APTR aptr;
  55.     char *pointer;
  56.     BPTR index_mulder=NULL,
  57.          data_mulder=NULL,
  58.          mulder=NULL,
  59.          lock=NULL,
  60.          lock2=NULL;
  61.     ULONG    index_size,
  62.             data_size,
  63.             ulong,
  64.             counter;
  65.     struct Subboard *subboard;
  66.     struct ItemHeader *itemheader;
  67.     struct Item *item;
  68.     struct FileInfoBlock *fib;
  69.     struct ViewItem *viewitem=0;
  70.     struct ViewList vlist;
  71.     struct ViewTable viewtable;
  72.     struct IndexEntry *indexentry;
  73.     struct IndexEntry *indexentry2;
  74.     struct IndexHeader indexheader;
  75.     struct Reply *reply;
  76.     struct MyNode *currentdir=0;
  77.     struct MyNode *newdir=0;
  78.     struct SelectItem *select;
  79.     ULONG dircounter=0;
  80.     ULONG itemcounter=0;
  81.     BOOL readnew=TRUE;
  82.  
  83.     if (!cport)return;
  84.  
  85.     NewList(&dirlist);
  86.  
  87.     sprintf(root,"%sroot/",cport->sysdirs->sysdata);
  88.     ClearMemQuick(&viewtable,sizeof(ViewTable));
  89.  
  90.     if (!(fib=AllocDosObject(DOS_FIB,NULL)))Quit=TRUE;
  91.     if (!(item=AllocVec(sizeof(Item),MEMF_ANY|MEMF_CLEAR)))Quit=TRUE;
  92. //    if (!(viewtable.item=AllocVec(viewtable.maxitems*sizeof(ViewItem),MEMF_ANY)))Quit=TRUE;
  93.     if (!(indexentry=AllocVec(sizeof(IndexEntry),MEMF_ANY)))Quit=TRUE;
  94.     if (!(reply=AllocVec(sizeof(Reply),MEMF_ANY)))Quit=TRUE;
  95.  
  96.     if (Quit)
  97.     {
  98.         if (fib)FreeDosObject(DOS_FIB,fib);
  99.         if (item)FreeVec(item);
  100.         if (viewtable.item)FreeVec(viewtable.item);
  101.         if (indexentry)FreeVec(indexentry);
  102.         if (reply)FreeVec(reply);
  103.         return;
  104.     }
  105.  
  106.     subboard=(Subboard *)item;
  107.     itemheader=(ItemHeader *)item;
  108.  
  109.     if (!(lock=Lock(root,SHARED_LOCK)))
  110.     {
  111.         if (!(lock=CreateDir(root)))
  112.             Quit=TRUE;
  113.         else
  114.             ChangeMode(CHANGE_LOCK,lock,SHARED_LOCK);
  115.     }
  116.     if (lock)
  117.     {
  118.         if (NameFromLock(lock,buffer,255))
  119.         {
  120.             strcpy(path,buffer);
  121.             strcat(path,"/data/.index");
  122.             if (currentdir=AllocVec(sizeof(Node),MEMF_ANY|MEMF_CLEAR))
  123.             {
  124.                 if (currentdir->ln_Name=AllocVec(strlen(buffer)+1,MEMF_ANY))
  125.                 {
  126.                     strcpy(currentdir->ln_Name,buffer);
  127.                     AddTail(&dirlist,(Node *)currentdir);
  128. //                    sprintf(path,"%s/data",buffer);
  129.                     if (!(index_mulder=Open(path,MODE_READWRITE)))
  130.                     {
  131.                         if (lock2=CreateDir(path))
  132.                         {
  133.                             UnLock(lock2);
  134.                             strcat(path,"/.index");
  135.                             if (!(index_mulder=Open(path,MODE_READWRITE)))
  136.                             {
  137.                                 Quit=TRUE;
  138.                                 ioprintf("can't create root.index.\n");
  139.                             }
  140.                         }
  141.                         else
  142.                         {
  143.                             ioprintf("can't create root/data directory.\n");
  144.                             Quit=TRUE;
  145.                         }
  146.                     }
  147.                 }
  148.                 else
  149.                 {
  150.                     FreeVec(currentdir);
  151.                     Quit=TRUE;
  152.                 }
  153.             }
  154.         }
  155.         UnLock(lock);
  156.         if (index_mulder)
  157.         {
  158.             Seek(index_mulder,0,OFFSET_END);
  159.             index_size=Seek(index_mulder,0,OFFSET_END);
  160.             if (Seek(index_mulder,0,OFFSET_BEGINNING)>=sizeof(IndexHeader))
  161.             {
  162.                 Read(index_mulder,&indexheader,sizeof(IndexHeader));
  163.             }
  164.             else
  165.             {
  166.                 ClearMemQuick(&indexheader,sizeof(IndexHeader));
  167.                 Write(index_mulder,&indexheader.Entrys,4);
  168.                 ioprintf("index mulder is empty\n");
  169.             }
  170.             Close(index_mulder);
  171.         }
  172.         else
  173.         {
  174.             Quit=TRUE;
  175.             ioprintf("can't open %s\n",path);
  176.         }
  177.     }
  178.     while (!Quit && !cport->ProgramClose && cport->network.online)
  179.     {
  180.         if (readnew)
  181.         {
  182.             if (viewtable.item)FreeVec(viewtable.item);
  183.             ClearMemQuick(&indexheader,sizeof(IndexHeader));
  184.             viewtable.item=0;
  185.             itemcounter=0;
  186.             dircounter=0;
  187.             viewtable.items=0;
  188.             viewtable.maxitems=0;
  189.             strcpy(path,currentdir->ln_Name);
  190.             strcat(path,"/data/.index");
  191.             if (index_mulder=Open(path,MODE_READWRITE))
  192.             {
  193.                 Seek(index_mulder,0,OFFSET_BEGINNING);
  194.                 Read(index_mulder,&indexheader,sizeof(IndexHeader));
  195.             }
  196.             else
  197.             {
  198.                 ioprintf("can't open %s.\n",path);
  199.             }
  200.             if (indexheader.Entrys)
  201.             {
  202.                 strcpy(path,currentdir->ln_Name);
  203.                 strcat(path,"/data/.data");
  204.                 data_mulder=Open(path,MODE_READWRITE);
  205.                 Quit2=FALSE;
  206.                 counter=0;
  207.                 ClearMemQuick(&viewtable,sizeof(ViewTable));
  208.                 if (viewtable.item=AllocVec(sizeof(ViewItem)*(indexheader.Entrys+200),MEMF_ANY|MEMF_CLEAR))
  209.                 {
  210.                     viewtable.maxitems=indexheader.Entrys+200;
  211.                     while (!Quit2)
  212.                     {
  213.                         if (Read(index_mulder,indexentry,sizeof(IndexEntry))<sizeof(IndexEntry))Quit2=TRUE;
  214.                         if (!Quit2)
  215.                         {
  216.                             if (Seek(data_mulder,indexentry->offset,OFFSET_BEGINNING)>-1)
  217.                             {
  218.                                 viewtable.maxitems=indexheader.Entrys+200;
  219.                                 if (indexentry->type==ITEMTYPE_SUBBOARD)
  220.                                 {
  221.                                     if (Read(data_mulder,itemheader,sizeof(Subboard))==sizeof(Subboard))
  222.                                     {
  223.                                         select=(SelectItem *)cport->select_list.mlh_Head;
  224.                                         while (select->ln_Succ)
  225.                                         {
  226.                                             if (select->dirIP==currentdir->IPNumber && select->itemIP==itemheader->IPNumber)
  227.                                                 viewtable.item[viewtable.items].select=TRUE;
  228.                                             select=select->ln_Succ;
  229.                                         }
  230.                                         dircounter++;
  231.                                         viewtable.item[viewtable.items].ItemType=indexentry->type;
  232.                                         viewtable.item[viewtable.items].Seek=indexentry->offset;
  233.                                         viewtable.item[viewtable.items].ListID=counter;
  234.                                         viewtable.item[viewtable.items].IndexID=counter++;
  235.                                         viewtable.item[viewtable.items].ItemIP=itemheader->IPNumber;
  236.                                         ItemToViewItem(itemheader,&viewtable.item[viewtable.items]);
  237.                                         viewtable.items++;
  238.                                     }
  239.                                     else
  240.                                     {
  241.                                         Quit2=TRUE;
  242.                                     }
  243.                                 }
  244.                                 else
  245.                                 {
  246.                                     if (Read(data_mulder,itemheader,sizeof(Item))==sizeof(Item))
  247.                                     {
  248.                                         select=(SelectItem *)cport->select_list.mlh_Head;
  249.                                         while (select->ln_Succ)
  250.                                         {
  251.                                             if (select->dirIP==currentdir->IPNumber && select->itemIP==itemheader->IPNumber)
  252.                                                 viewtable.item[viewtable.items].select=TRUE;
  253.                                             select=select->ln_Succ;
  254.                                         }
  255.                                         itemcounter++;
  256.                                         viewtable.item[viewtable.items].ItemType=indexentry->type;
  257.                                         viewtable.item[viewtable.items].Seek=indexentry->offset;
  258.                                         viewtable.item[viewtable.items].ListID=counter;
  259.                                         viewtable.item[viewtable.items].ItemIP=itemheader->IPNumber;
  260.                                         viewtable.item[viewtable.items].IndexID=counter++;
  261.                                         ItemToViewItem(itemheader,&viewtable.item[viewtable.items]);
  262.                                         viewtable.items++;
  263.                                     }
  264.                                     else
  265.                                     {
  266.                                         Quit2=TRUE;
  267.                                     }
  268.                                 }
  269.                             }
  270.                             else
  271.                             {
  272.                                 Quit2=TRUE;
  273.                             }
  274.                         }
  275.                         else
  276.                         {
  277.                             Quit2=TRUE;
  278.                         }
  279.                     }
  280.                 }
  281.                 if (data_mulder)Close(data_mulder);
  282.             }
  283.             readnew=FALSE;
  284.             if (index_mulder)Close(index_mulder);
  285.             if (indexheader.Entrys)
  286.             {
  287.                 ioprintf("Subboardname: c7%s c2SerialIP: %05d\n",currentdir->ln_Name,currentdir->IPNumber);
  288.                 LF();
  289.                 for (counter=0; counter<indexheader.Entrys; counter++)
  290.                     ioprintf("%s\n",viewtable.item[counter].Title);
  291.                 ioprintf("c7%d c3directories - c7%d c3items\n",dircounter,itemcounter);
  292.             }
  293.             else
  294.             {
  295.                 ioprintf("\nDirectory is empty\n");
  296.             }
  297.         }
  298.         ioprintf("\nc7%d.%s>",cport->clientconfig.IDNumber,currentdir->ln_Name);
  299.         Getstring(buffer,0,50,0,0);
  300.         GetArg(buffer);
  301.         nostdcmd=TRUE;
  302.         switch(cmdid=GetCommandID(cport->argstring[0]))
  303.         {
  304.             /****************************************************************************/
  305.             case CMD_REPAIR:
  306.                 RepairBase();
  307.                 nostdcmd=FALSE;                
  308.                 break;
  309.             case CMD_EDIT:
  310.                 StrToLong(cport->argstring[1],(LONG *)&ulong);ulong--;
  311.                 if (ulong>=0 && ulong<indexheader.Entrys)
  312.                 {
  313.                     strcpy(path,currentdir->ln_Name);
  314.                     strcat(path,"/data/.data");
  315.                     if (data_mulder=Open(path,MODE_READWRITE))
  316.                     {
  317.                         Seek(data_mulder,viewtable.item[ulong].Seek,OFFSET_BEGINNING);
  318.                         if (viewtable.item[ulong].ItemType==ITEMTYPE_SUBBOARD)
  319.                         {
  320.                             if (FRead(data_mulder,subboard,sizeof(Subboard),1))
  321.                             {
  322.                                 if (VDE(VDEID_SUBBOARD,(char *)subboard)==TRUE)
  323.                                 {
  324.                                     Seek(data_mulder,viewtable.item[ulong].Seek,OFFSET_BEGINNING);
  325.                                     FWrite(data_mulder,subboard,sizeof(Subboard),1);
  326.                                     readnew=TRUE;
  327.                                 }
  328.                             }
  329.                         }
  330.                         else
  331.                         {
  332.                             if (FRead(data_mulder,item,sizeof(Item),1))
  333.                             {
  334.                             }
  335.                         }
  336.                         Close(data_mulder);
  337.                     }
  338.                 }
  339.                 else
  340.                 {
  341.                     ioprintf("invalid Itemnumber: %d\n",ulong);
  342.                 }
  343.                 nostdcmd=FALSE;
  344.                 break;
  345.             case CMD_ADOPT_ORPHANS:
  346.                 ioprintf("\nEnter directory :> ",-1);
  347.                 Getstring(buffer,0,50,0,0);
  348.                 ioprintf("\n");
  349.                 if (lock2=Lock(buffer,SHARED_LOCK))
  350.                 {
  351.                     Examine(lock2,fib);
  352.                     Quit2=FALSE;
  353.                     NewList((List *)&vlist);
  354.                     vlist.entrys=0;
  355.                     NameFromLock(lock2,odir,256);
  356.                     while (ExNext(lock2,fib) && !Quit2)
  357.                     {
  358.                         if (fib->fib_DirEntryType==ST_FILE)
  359.                         {
  360.                             sprintf(buffer,"c7Add %s ? [c1Yc7es,No,Stop,Cancel]>",fib->fib_FileName);
  361.                             ioprintf("\n");
  362.                             Writeio(buffer,-1);
  363.                             switch (GetChar("",0))
  364.                             {
  365.                                 case 'Y':case 'y':
  366.                                     Writeio("Yes",-1);
  367.                                     if (viewitem=AllocVec(sizeof(ViewItem),MEMF_ANY|MEMF_CLEAR))
  368.                                     {
  369.                                         strcpy(viewitem->Title,fib->fib_FileName);
  370.                                         AddTail((List *)&vlist,(Node *)viewitem);
  371.                                         viewitem->Size=(LONG)fib->fib_Size;
  372.                                         vlist.entrys++;
  373.                                     }
  374.                                     break;
  375.                                 case 'N':case 'n':
  376.                                     Writeio("No",-1);
  377.                                     break;
  378.                                 case 'S':case 's':
  379.                                     Writeio("Stop",-1);
  380.                                     Quit2=TRUE;
  381.                                     break;
  382.                                 case 'C':case 'c':
  383.                                     Writeio("Cancel",-1);
  384.                                     while (!IsListEmpty((List *)&vlist))
  385.                                     {
  386.                                         viewitem=vlist.lh_Head;
  387.                                         Remove((Node *)viewitem);
  388.                                         FreeVec(viewitem);
  389.                                     }
  390.                                     Quit2=TRUE;
  391.                                     break;
  392.                             }
  393.                         }
  394.                     }
  395.                     UnLock(lock2);
  396.                     ioprintf("\n");
  397.                     strcpy(path,currentdir->ln_Name);
  398.                     strcat(path,"/data/.index");
  399.                     if (index_mulder=Open(path,MODE_READWRITE))
  400.                     {
  401.                         strcpy(path,currentdir->ln_Name);
  402.                         strcat(path,"/data/.data");
  403.                         if (data_mulder=Open(path,MODE_READWRITE))
  404.                         {
  405.                             if (indexheader.Entrys+vlist.entrys>=viewtable.maxitems)
  406.                             {
  407.                                 if (viewitem=AllocVec(sizeof(ViewItem)*(indexheader.Entrys+vlist.entrys+200),MEMF_ANY|MEMF_CLEAR))
  408.                                 {
  409.                                     if (viewtable.item)
  410.                                     {
  411.                                         FreeVec(viewtable.item);
  412.                                         CopyMemQuick(viewitem,viewtable.item,indexheader.Entrys*sizeof(ViewItem));
  413.                                     }
  414.                                     viewtable.maxitems = indexheader.Entrys+vlist.entrys+200;
  415.                                     viewtable.item         = viewitem;
  416.                                 }
  417.                             }
  418.                             ioprintf("\nalloc: %u - entrys %u size: %u\n",sizeof(IndexEntry)*vlist.entrys,vlist.entrys,sizeof(IndexEntry));
  419.                             if (indexentry2=AllocVec(sizeof(IndexEntry)*vlist.entrys,MEMF_ANY|MEMF_CLEAR))
  420.                             {
  421.                                 if (item=AllocVec(sizeof(Item)*vlist.entrys,MEMF_ANY|MEMF_CLEAR))
  422.                                 {
  423.                                     Seek(data_mulder,0,OFFSET_END);
  424.                                     ulong=Seek(data_mulder,0,OFFSET_END);    // get offset for .index-entry
  425.                                     counter=0;
  426.                                     while (!IsListEmpty((List *)&vlist))
  427.                                     {
  428.                                         /*** Get a entrys from edit ViewList (vlist) ***/
  429.                                             viewitem=vlist.lh_Head;
  430.     
  431.                                         /*** init itemstructure, adding user, itemtype, time etc ***/
  432.     
  433.                                         item[counter].itemheader.ItemType=ITEMTYPE_FILEITEM;
  434.                                         strcpy(item[counter].itemheader.Title,viewitem->Title);
  435.                                         strcpy(item[counter].itemheader.Path,currentdir->ln_Name);
  436.                                         strcat(item[counter].itemheader.Path,viewitem->Title);
  437.                                         item[counter].FromUser=cport->LocalUser.IDNumber;
  438.                                         item[counter].ItemType=1;
  439.                                         strcpy(item[counter].Name,cport->LocalUser.Handle);
  440.                                         strcpy(item[counter].FromRealName,cport->LocalUser.RealName);
  441.                                         sprintf(item[counter].Filename,"%s/%s",odir,viewitem->Title);
  442.                                         GetTime(&item[counter].SendDate);
  443.                                         GetTime(&item[counter].itemheader.CreateDate);    
  444.                                         GetTime(&item[counter].itemheader.LastChange);
  445.                                         item[counter].Size=viewitem->Size;
  446.     
  447.                                         /*** End of .data-file is the offset for new subboard-structure ***/
  448.     
  449.                                         indexentry2[counter].offset=ulong;
  450.                                         ulong=ulong+sizeof(Item);
  451.  
  452.                                         /*** Calculating IDNumber of subboard ***/
  453.     
  454.                                         item[counter].itemheader.IDNumber=indexheader.idcounter++;
  455.     
  456.                                         /*** Adding item-entry ***/
  457.     
  458.                                         indexentry2[counter].type=item[counter].itemheader.ItemType;
  459.  
  460.                                         /*** Remove Entry from edit viewlist and Add Entry to System-Viewlist ***/
  461.     
  462.                                         Remove((Node *)viewitem);
  463.                                         if (viewtable.items<viewtable.maxitems)
  464.                                         {
  465.                                             itemcounter++;
  466.                                             viewitem->ItemType=item[counter].itemheader.ItemType;
  467.                                             viewitem->Seek=indexentry2[counter].offset;
  468.                                             viewitem->ListID=indexheader.Entrys;
  469.                                             viewitem->IndexID=indexheader.Entrys;
  470.                                             ItemToViewItem(&item[counter].itemheader,viewitem);                // Fill viewitem->Title with item-datas
  471.                                             CopyMemQuick(viewitem,&viewtable.item[viewtable.items],sizeof(ViewItem));
  472.                                             viewtable.items++;
  473.                                         }
  474.                                         FreeVec(viewitem);
  475.                                         indexheader.Entrys++;
  476.                                         counter++;
  477.                                     }
  478.                                     Seek(index_mulder,0,OFFSET_BEGINNING);
  479.                                     Write(index_mulder,&indexheader,sizeof(IndexHeader));
  480.                                     Seek(index_mulder,0,OFFSET_END);
  481.                                     Write(index_mulder,indexentry2,sizeof(IndexEntry)*vlist.entrys);
  482.                                     Seek(data_mulder,0,OFFSET_END);
  483.                                     Write(data_mulder,item,sizeof(Item)*vlist.entrys);
  484.                                     FreeVec(item);
  485.                                     item=(Item *)subboard;
  486.                                     LF();
  487.                                     for (counter=0; counter<indexheader.Entrys; counter++)
  488.                                         ioprintf("%s\n",viewtable.item[counter].Title);
  489.                                     ioprintf("c7%d c3directories - c7%d c3items\n",dircounter,itemcounter);
  490.                                 }
  491.                                 else
  492.                                 {
  493.                                     ioprintf("\nCan't alloc mem for item.\n");
  494.                                 }
  495.                                 FreeVec(indexentry2);
  496.                             }
  497.                             else
  498.                             {
  499.                                 ioprintf("\nCan't alloc mem for indexentry\n");
  500.                             }
  501.                             Close(index_mulder);
  502.                             Close(data_mulder);
  503.                             }
  504.                         else
  505.                         {
  506.                             Close(index_mulder);
  507.                         }
  508.                     }
  509.                 }
  510.                 nostdcmd=FALSE;
  511.                 break;
  512.                 /**************************************************************************/
  513.                 case CMD_SUBBOARD_NEW:
  514.                     ClearMemQuick(subboard,sizeof(Subboard));
  515.                 ioprintf("\nc7Please Enter the name of subboard\n :> ");
  516.                 Getstring(itemheader->Title,0,50,0,0);
  517.                 if (strlen(itemheader->Title)>=3)
  518.                 {
  519.                     ioprintf("\nc7Please Enter the pathname (without /\/././\/./\.).\n:> ");
  520.                     sprintf(buffer,"%s/%s",currentdir->ln_Name,itemheader->Title);
  521.                     Getstring(itemheader->Path,buffer,70,0,0);
  522.                     if (!strlen(itemheader->Path))
  523.                     {
  524.                         strcpy(itemheader->Path,itemheader->Title);
  525.                         Writeio(itemheader->Path,-1);
  526.                     }
  527.                     if (strlen(itemheader->Path)>=3)
  528.                     {
  529.                         if (VDE(VDEID_SUBBOARD,(char *)subboard)==TRUE)
  530.                         {
  531.                             itemheader->ItemType=ITEMTYPE_SUBBOARD;
  532.                             if (AddItem(itemheader,(char *)currentdir->ln_Name))
  533.                             {
  534.                                     strcpy(currentdir->ln_Name,itemheader->Path);
  535.                                 /*** Adding directory to list ***/
  536.                                     if (viewtable.items+1>=viewtable.maxitems)
  537.                                 {
  538.                                     if (viewitem=AllocVec(sizeof(ViewItem)*(viewtable.maxitems+200),MEMF_ANY|MEMF_CLEAR))
  539.                                     {
  540.                                         if (viewtable.item)
  541.                                         {
  542.                                             FreeVec(viewtable.item);
  543.                                             CopyMemQuick(viewtable.item,viewitem,viewtable.items*sizeof(ViewItem));
  544.                                         }
  545.                                         viewtable.item=viewitem;
  546.                                         viewtable.maxitems=viewtable.maxitems+200;
  547.                                     }
  548.                                 }
  549.                                 if (viewtable.items<viewtable.maxitems)
  550.                                 {
  551.                                     dircounter++;
  552.                                     viewtable.item[viewtable.items].ItemType=itemheader->ItemType;
  553.                                     viewtable.item[viewtable.items].Seek=itemheader->IndexOffset;
  554.                                     viewtable.item[viewtable.items].ListID=indexheader.Entrys;
  555.                                     viewtable.item[viewtable.items].IndexID=indexheader.Entrys++;
  556.                                     ItemToViewItem(itemheader,&viewtable.item[viewtable.items]);
  557.                                     viewtable.items++
  558.                                 }
  559.                                 else
  560.                                 {
  561.                                     ErrorMessage("Can't add directory to displaylist, not anouth memory.");
  562.                                 }
  563.                             }
  564.                         }
  565.                     }
  566.                     else
  567.                     {
  568.                         Writeio("the minimum length of path must be 3 chars!",-1);
  569.                     }
  570.                 }
  571.                 else
  572.                 {
  573.                     Writeio("the minimum length of title must be 3 chars!",-1);
  574.                 }
  575.                 nostdcmd=FALSE;
  576.                 break;
  577.             /****************************************************************************/
  578.             case CMD_LIST: case CMD_DIR: case CMD_BROWSE:
  579.                 LF();
  580.                 for (counter=0; counter<indexheader.Entrys; counter++)
  581.                     ioprintf("%s\n",viewtable.item[counter].Title);
  582.                 ioprintf("c7%d c3directories - c7%d c3items\n",dircounter,itemcounter);
  583.                 nostdcmd=FALSE;
  584.                 break;
  585.             case CMD_DEL:
  586.                 if (ArgToLong(cport->argstring[1],&start,&end))
  587.                 {
  588.                     start--;end--;
  589.                     DelItem(currentdir->ln_Name,start,end);
  590.                 }
  591.                 else
  592.                 {
  593.                     ioprintf("\nUSAGE: delete [FROM]-[TO] | [ALL]\n");
  594.                 }
  595.                 nostdcmd=FALSE;
  596.                 break;
  597.             case CMD_PARRENT:
  598.                 if (currentdir->ln_Pred->ln_Pred)
  599.                 {
  600.                     ioprintf("search select items \n");
  601.                     for (counter=0; counter<indexheader.Entrys; counter++)
  602.                     {
  603.                         ioprintf("counting %d\n",counter);
  604.                         if (viewtable.item[counter].ItemIP)
  605.                         {
  606.                             char q=FALSE;
  607.                             ioprintf("select: %d\n",viewtable.item[counter].ItemIP);
  608.                             select=(SelectItem *)&cport->select_list.mlh_Head;
  609.                             while (!q && select->ln_Succ)
  610.                             {
  611.                                 if (select->dirIP==currentdir->IPNumber &&
  612.                                     select->itemIP==viewtable.item[counter].ItemIP)q=TRUE;
  613.                                 if (!q)select=select->ln_Succ;
  614.                             }
  615.                             if (viewtable.item[counter].select)
  616.                             {
  617.                                 if (!q)
  618.                                 {
  619.                                     if (select=AllocVec(sizeof(SelectItem),MEMF_ANY|MEMF_CLEAR))
  620.                                     {
  621.                                         select->dirIP=currentdir->IPNumber;
  622.                                         select->itemIP=viewtable.item[counter].ItemIP;
  623.                                         AddTail((List *)&cport->select_list,(Node *)select);
  624.                                     }
  625.                                 }
  626.                             }
  627.                             else
  628.                             {
  629.                                 if (q && select)
  630.                                 {
  631.                                     Remove((Node *)select);
  632.                                     FreeVec(select);
  633.                                 }
  634.                             }
  635.                         }
  636.                     }                    
  637.                     newdir=currentdir->ln_Pred;
  638.                     Remove((Node *)currentdir);
  639.                     if (currentdir->ln_Name)
  640.                         FreeVec(currentdir->ln_Name);
  641.                     FreeVec(currentdir);
  642.                     currentdir=newdir;
  643.                     readnew=TRUE;
  644.                 }                
  645.                 else
  646.                 {
  647.                     Quit=TRUE;
  648.                 }                
  649.                 nostdcmd=FALSE;
  650.                 break;
  651.             case CMD_POST:
  652.                 ClearMemQuick(item,sizeof(Item));
  653.                 ioprintf("\nc7Subject:> ");
  654.                 Getstring(itemheader->Title,0,50,0,0);
  655.                 if (strlen(itemheader->Title)>=3)
  656.                 {
  657.                     if (VisualEditor("ram:temp"))
  658.                     {
  659.                         if (mulder=Open("ram:temp",MODE_OLDFILE))
  660.                         {
  661.                             Seek(mulder,0,OFFSET_END);
  662.                             if (ulong=Seek(mulder,0,OFFSET_BEGINNING))
  663.                             {
  664.                                 aptr=AllocVec(ulong,MEMF_ANY);
  665.                                 FRead(mulder,aptr,ulong,1);
  666.                                     strcpy(path,currentdir->ln_Name);
  667.                                 strcat(path,"/data/.index");
  668.                                 if (index_mulder=Open(path,MODE_READWRITE))
  669.                                 {
  670.                                     sprintf(path,"%s/data/%x.text",currentdir->ln_Name,indexheader.idcounter+1);
  671.                                     if (data_mulder=Open(path,MODE_NEWFILE))
  672.                                     {
  673.                                         FWrite(data_mulder,aptr,ulong,1);
  674.                                         item->seek=0;
  675.                                         item->length=Seek(data_mulder,0,OFFSET_END);
  676.                                         Close(data_mulder);
  677.                                             sprintf(item->itemheader.Path,"%x",indexheader.idcounter+1);
  678.                                 
  679.                                         strcpy(path,currentdir->ln_Name);
  680.                                         strcat(path,"/data/.data");
  681.                                         if (data_mulder=Open(path,MODE_READWRITE))
  682.                                         {
  683.                                             /*** Adding Username & ID of Creater ***/
  684.     
  685.                                             itemheader->ItemType=ITEMTYPE_ITEM;
  686.                                             item->FromUser=cport->LocalUser.IDNumber;
  687.                                             item->ItemType=1;
  688.                                             strcpy(item->Name,cport->LocalUser.Handle);
  689.                                             strcpy(item->FromRealName,cport->LocalUser.RealName);
  690.                                             strcpy(item->Filename,cport->LocalUser.Handle);
  691.                                             GetTime(&itemheader->CreateDate);
  692.                                             GetTime(&itemheader->LastChange);
  693.     
  694.                                             /*** End of .data-file is the offset for new subboard-structure ***/
  695.     
  696.                                             ClearMemQuick(indexentry,sizeof(IndexEntry));
  697.                                             Seek(data_mulder,0,OFFSET_END);
  698.                                             indexentry->offset=Seek(data_mulder,0,OFFSET_END);
  699.         
  700.                                             /*** Calculating IDNumber of subboard ***/
  701.     
  702.                                             itemheader->IDNumber=indexheader.idcounter++;
  703.                                             Seek(index_mulder,0,OFFSET_BEGINNING);
  704.                                             indexheader.Entrys++;
  705.                                             Write(index_mulder,&indexheader,sizeof(IndexHeader));
  706.     
  707.                                             /*** Adding subboard-Entry in .index ***/
  708.     
  709.                                             indexentry->type=itemheader->ItemType;
  710.                                             Seek(index_mulder,0,OFFSET_END);
  711.                                             Write(index_mulder,indexentry,sizeof(IndexEntry));    // fill up to 20 Bytes
  712.     
  713.                                             /*** Saveing Subdir-Structure in .data and closing X-Files ***/
  714.     
  715.                                             Write(data_mulder,item,sizeof(Item));
  716.                                             Close(data_mulder);
  717.                                             Close(index_mulder);        
  718.     
  719.                                             /*** Adding Item to list ***/
  720.     
  721.                                             if ((viewtable.items+1)>=viewtable.maxitems)
  722.                                             {
  723.                                                 if (viewitem=AllocVec(sizeof(ViewItem)*(viewtable.maxitems+200),MEMF_ANY|MEMF_CLEAR))
  724.                                                 {
  725.                                                     if (viewtable.maxitems)CopyMemQuick(viewtable.item,viewitem,(viewtable.maxitems+200)*sizeof(ViewItem));
  726.                                                     viewtable.maxitems=viewtable.maxitems+200;
  727.                                                     FreeVec(viewtable.item);
  728.                                                     viewtable.item=viewitem;
  729.                                                 }
  730.                                             }
  731.                                             if (viewtable.items<viewtable.maxitems)
  732.                                             {
  733.                                                 itemcounter++;
  734.                                                 viewtable.item[viewtable.items].ItemType=itemheader->ItemType;
  735.                                                 viewtable.item[viewtable.items].Seek=indexentry->offset;
  736.                                                 viewtable.item[viewtable.items].ListID=indexheader.Entrys;
  737.                                                 viewtable.item[viewtable.items].IndexID=indexheader.Entrys++;
  738.                                                 ItemToViewItem(itemheader,&viewtable.item[viewtable.items]);
  739.                                                 viewtable.items++
  740.                                             }
  741.                                             else
  742.                                             {
  743.                                                 ErrorMessage("Can't add directory to displaylist, out of memory.");
  744.                                             }
  745.                                         }
  746.                                         else
  747.                                         {
  748.                                             Close(index_mulder);
  749.                                             ioprintf("\nCan't open %s. ",path);
  750.                                             PrintDosError(IoErr());
  751.                                         }
  752.                                     }
  753.                                     else
  754.                                     {
  755.                                         ulong=(LONG)IoErr();
  756.                                         ioprintf("\nCan't open %s. ",path);
  757.                                         PrintDosError(IoErr());
  758.                                     }
  759.                                 }
  760.                                 else
  761.                                 {
  762.                                     ulong=(LONG)IoErr();
  763.                                     ioprintf("Can't open %s. ",path);
  764.                                     PrintDosError(IoErr());
  765.                                 }
  766.                                 FreeVec(aptr);
  767.                             }
  768.                             else
  769.                             {
  770.                                 ioprintf("\nral:temp is empty.Tn");
  771.                             }
  772.                             Close(mulder);
  773.                         }
  774.                         else
  775.                         {
  776.                             ioprintf("\nCan't open ram:temp\n");
  777.                         }
  778.                     }
  779.                 }
  780.                 nostdcmd=FALSE;
  781.                 break;
  782.             case CMD_HELP:
  783.                 sprintf(buffer,"%ssys.base.text",cport->sysdirs->systext);
  784.                 ShowText(buffer);LF();
  785.                 nostdcmd=FALSE;
  786.                 break;
  787.             case CMD_QUIT:
  788.                 Quit=TRUE;
  789.                 nostdcmd=FALSE;
  790.                 break;
  791.             case CMD_DOWNLOAD_DIRECT:
  792.                 {
  793.                     struct SelectItem *select;
  794.                     ULONG start = 0,
  795.                             end    = 0;
  796.                     if (ArgToLong(cport->argstring[1],&start,&end))
  797.                     {
  798.                         char quit=FALSE;
  799.                         start--;end--;
  800.                         if (end > indexheader.Entrys)
  801.                             end = indexheader.Entrys-1;
  802.  
  803.                         for (start=start; start<end; start++)
  804.                         {
  805.                             if (select=AllocVec(sizeof(SelectItem),MEMF_ANY|MEMF_CLEAR))
  806.                             {
  807.                                 select->dirIP    = currentdir->IPNumber;
  808.                                 select->itemIP    = viewtable.item[start].ItemIP;
  809.                                 select->downloadnow=2;                                            // 2, to find direct download files
  810.                                 AddTail((List *)&cport->select_list,(Node *)select);
  811.                             }
  812.                         }
  813.  
  814.                         select=(SelectItem *)cport->select_list.mlh_Head;
  815.                         cport->actual = NULL;                                                    // reset actual download file
  816.                         while (select->ln_Succ && !quit)
  817.                         {
  818.                             if (select->downloadnow == 2)                                        // searching for first direct download file
  819.                             {
  820.                                 cport->actual = select;                                            // set first file to download
  821.                                 quit = TRUE;
  822.                             }
  823.                             select=select->ln_Succ;
  824.                         }
  825.                         if (quit)
  826.                             DoTransfer();                                                            // if quit == TRUE, selected files was ok.
  827.                     }
  828.                     else
  829.                     {
  830.                         ioprintf("\nUSAGE: delete [FROM]-[TO] | [ALL]\n");
  831.                     }
  832.                 }
  833.                 nostdcmd=FALSE;
  834.                 break;
  835.  
  836.         }
  837.         if (nostdcmd)
  838.         {
  839.             if (!StdCommand(cmdid) && *buffer)
  840.             {
  841.                 StrToLong(cport->argstring[0],(long *)&ulong);
  842.                 ulong--;
  843.                 if (ulong>=0 && ulong<indexheader.Entrys)
  844.                 {
  845.                     strcpy(path,currentdir->ln_Name);
  846.                     strcat(path,"/data/.data");
  847.                     if (data_mulder=Open(path,MODE_OLDFILE))
  848.                     {
  849.                         Seek(data_mulder,viewtable.item[ulong].Seek,OFFSET_BEGINNING);
  850.                         if (viewtable.item[ulong].ItemType==ITEMTYPE_SUBBOARD)
  851.                         {
  852.                             if (FRead(data_mulder,subboard,sizeof(Subboard),1))
  853.                             {
  854.                                 if (newdir=AllocVec(sizeof(Node),MEMF_ANY|MEMF_CLEAR))
  855.                                 {
  856.                                     if (newdir->ln_Name=AllocVec(strlen(itemheader->Path)+1,MEMF_ANY|MEMF_CLEAR))
  857.                                     {
  858.                                         for (counter=0; counter<indexheader.Entrys; counter++)
  859.                                         {
  860.                                             if (viewtable.item[counter].ItemIP)
  861.                                             {
  862.                                                 char q=FALSE;
  863.                                                 select=(SelectItem *)&cport->select_list.mlh_Head;
  864.                                                 while (!q && select->ln_Succ)
  865.                                                 {
  866.                                                     if (select->dirIP==currentdir->IPNumber &&
  867.                                                         select->itemIP==viewtable.item[counter].ItemIP)q=TRUE;
  868.                                                     if (!q)select=select->ln_Succ;
  869.                                                 }
  870.                                                 if (viewtable.item[counter].select)
  871.                                                 {
  872.                                                     if (!q)
  873.                                                     {
  874.                                                         if (select=AllocVec(sizeof(SelectItem),MEMF_ANY|MEMF_CLEAR))
  875.                                                         {
  876.                                                             select->dirIP=currentdir->IPNumber;
  877.                                                             select->itemIP=viewtable.item[counter].ItemIP;
  878.                                                             AddTail((List *)&cport->select_list,(Node *)select);
  879.                                                         }
  880.                                                     }
  881.                                                 }
  882.                                                 else
  883.                                                 {
  884.                                                     if (q && select)
  885.                                                     {
  886.                                                         Remove((Node *)select);
  887.                                                         FreeVec(select);
  888.                                                     }
  889.                                                 }
  890.                                             }
  891.                                         }
  892.                                         strcpy(newdir->ln_Name,itemheader->Path);
  893.                                         AddTail(&dirlist,(Node *)newdir);
  894.                                         currentdir=newdir;
  895.                                         currentdir->IPNumber=itemheader->IPNumber;
  896.                                         readnew=TRUE;
  897.                                     }
  898.                                     else
  899.                                     {
  900.                                         ioprintf("Can't change directory, out of memory\n");
  901.                                         FreeVec(newdir);
  902.                                     }
  903.                                 }
  904.                             }
  905.                         }
  906.                         else
  907.                         {
  908.                             if (FRead(data_mulder,item,sizeof(Item),1))
  909.                             {
  910.                                 ReadSubboard(item,currentdir->ln_Name);
  911.                                 readnew=TRUE;
  912.                             }
  913.                         }
  914.                         Close(data_mulder);
  915.                     }
  916.                     else
  917.                         ioprintf("can't open: %s\n",path);
  918.                 }
  919.                 else
  920.                 {
  921.                     if (strlen(cport->argstring[0]))
  922.                     {
  923.                         if (*cport->argstring[0]=='*')
  924.                         {
  925.                             {
  926.                                 ULONG from=0;
  927.                                 ULONG to=0;
  928.                                 char *pt=cport->argstring[0];
  929.                                 while (*pt)
  930.                                 {
  931.                                     if (*pt>=48 && *pt<=57)
  932.                                     {
  933.                                         StrToLong(pt,(long *)&from);
  934.                                         while (*pt>=48 && *pt<=57)
  935.                                             pt++;
  936.                                         if (*pt=='-')
  937.                                         {
  938.                                             while (*pt && (*pt<48|*pt>57))
  939.                                                 pt++;
  940.                                             if (*pt>=48 && *pt<=57)
  941.                                             {
  942.                                                 StrToLong(pt,(long *)&to);
  943.                                                 while (*pt>=48 && *pt<=57)pt++;
  944.                                                 if (from>to)
  945.                                                 {
  946.                                                     ulong=to;
  947.                                                     to=from;
  948.                                                     from=ulong;
  949.                                                 }
  950.                                                 if (!from)from=1;
  951.                                                 for (ulong=from;(ulong<=indexheader.Entrys && ulong<=to);ulong++)
  952.                                                 {
  953.                                                     if (viewtable.item[ulong-1].select)
  954.                                                     {
  955.                                                         viewtable.item[ulong-1].select=FALSE;
  956.                                                         ioprintf("c3item c7%d c3is now deselected\n",ulong);
  957.                                                     }
  958.                                                     else
  959.                                                     {
  960.                                                         viewtable.item[ulong-1].select=TRUE;
  961.                                                         ioprintf("c3item c7%d c3is now selected\n",ulong);
  962.                                                     }
  963.                                                 }
  964.                                             }
  965.                                             else
  966.                                             {
  967.                                                 if (from && from<=indexheader.Entrys)
  968.                                                 {
  969.                                                     for (ulong=from-1;ulong<indexheader.Entrys;ulong++)
  970.                                                     {
  971.                                                         if (viewtable.item[ulong].select)
  972.                                                         {
  973.                                                             viewtable.item[ulong].select=FALSE;
  974.                                                             ioprintf("c3item c7%d c3is now deselected\n",ulong);
  975.                                                         }
  976.                                                         else
  977.                                                         {
  978.                                                             viewtable.item[ulong].select=TRUE;
  979.                                                             ioprintf("c3item c7%d c3is now selected\n",ulong);
  980.                                                         }
  981.                                                     }
  982.                                                 }
  983.                                             }
  984.                                         }
  985.                                         else
  986.                                         {
  987.                                             if (from>0 && from<=indexheader.Entrys)
  988.                                             {
  989.                                                 if (viewtable.item[from-1].select)
  990.                                                 {
  991.                                                     viewtable.item[from-1].select=FALSE;
  992.                                                     ioprintf("c3item c7%d c3is now deselected\n",from);
  993.                                                 }
  994.                                                 else
  995.                                                 {
  996.                                                     viewtable.item[from-1].select=TRUE;
  997.                                                     ioprintf("c3item c7%d c3is now selected\n",from);
  998.                                                 }
  999.                                             }
  1000.                                         }
  1001.                                     }
  1002.                                     else
  1003.                                     {
  1004.                                         if (*pt=='-')
  1005.                                         {
  1006.                                             while (*pt && (*pt<48|*pt>57))
  1007.                                                 pt++;
  1008.                                             if (*pt>=48 && *pt<=57)
  1009.                                             {
  1010.                                                 StrToLong(pt,(long *)&to);
  1011.                                                 if (to>indexheader.Entrys)to=indexheader.Entrys;
  1012.                                                 for (ulong=0;ulong<to;ulong++)
  1013.                                                 {
  1014.                                                     if (viewtable.item[ulong].select)
  1015.                                                     {
  1016.                                                         viewtable.item[ulong].select=FALSE;
  1017.                                                         ioprintf("c3item c7%d c3is now deselected\n",ulong+1);
  1018.                                                     }
  1019.                                                     else
  1020.                                                     {
  1021.                                                         viewtable.item[ulong].select=TRUE;
  1022.                                                         ioprintf("c3item c7%d c3is now selected\n",ulong+1);
  1023.                                                     }
  1024.                                                 }
  1025.                                             }
  1026.                                         }
  1027.                                     }
  1028.                                     if(*pt)pt++;
  1029.                                 }
  1030.                             }
  1031.                         }
  1032.                         else
  1033.                         {
  1034.                             if (ulong>0 && ulong<0xffffffff)
  1035.                                 ioprintf("\n%d: invalid Itemnumber",ulong);
  1036.                             else
  1037.                             {
  1038.                                 ioprintf("\n%s: Unknown command\n",cport->argstring[0]);
  1039.                                 sprintf(buffer,"%ssys.base.text",cport->sysdirs->systext);
  1040.                                 ShowText(buffer);LF();
  1041.                             }
  1042.                         }
  1043.                     }
  1044.                 }
  1045.             }
  1046.         }
  1047.     }
  1048.     if (indexheader.Entrys)
  1049.     {
  1050.         for (counter=0; counter<indexheader.Entrys; counter++)
  1051.         {
  1052.             if (viewtable.item[counter].ItemIP)
  1053.             {
  1054.                 char q=FALSE;
  1055.                 select=(SelectItem *)&cport->select_list.mlh_Head;
  1056.                 while (!q && select->ln_Succ)
  1057.                 {
  1058.                     if (select->dirIP==currentdir->IPNumber &&
  1059.                         select->itemIP==viewtable.item[counter].ItemIP)q=TRUE;
  1060.                     if (!q)select=select->ln_Succ;
  1061.                 }
  1062.                 if (viewtable.item[counter].select)
  1063.                 {
  1064.                     if (!q)
  1065.                     {
  1066.                         if (select=AllocVec(sizeof(SelectItem),MEMF_ANY|MEMF_CLEAR))
  1067.                         {
  1068.                             select->dirIP=currentdir->IPNumber;
  1069.                             select->itemIP=viewtable.item[counter].ItemIP;
  1070.                             AddTail((List *)&cport->select_list,(Node *)select);
  1071.                         }
  1072.                     }
  1073.                 }
  1074.                 else
  1075.                 {
  1076.                     if (q && select)
  1077.                     {
  1078.                         Remove((Node *)select);
  1079.                         FreeVec(select);
  1080.                     }
  1081.                 }
  1082.             }
  1083.         }                    
  1084.     }
  1085.     while (!IsListEmpty(&dirlist))
  1086.     {
  1087.         newdir=(MyNode *)RemHead(&dirlist);
  1088.         if (newdir->ln_Name)
  1089.             FreeVec(newdir->ln_Name);
  1090.         FreeVec(newdir);
  1091.     }
  1092.     if (fib)FreeDosObject(DOS_FIB,fib);
  1093.     if (item)FreeVec(item);
  1094.     if (viewtable.item)FreeVec(viewtable.item);
  1095.     if (indexentry)FreeVec(indexentry);
  1096.     if (reply)FreeVec(reply);
  1097. }    
  1098.  
  1099. struct smulder {
  1100.     struct smulder *ln_Succ;
  1101.     struct smulder *ln_Pred;
  1102.     UBYTE            ln_Type;
  1103.     BYTE            ln_Pri;
  1104.     BYTE             *ln_Name;
  1105.     BPTR            index_mulder;
  1106.     BPTR            data_mulder;
  1107.     BPTR            serial_mulder;
  1108. };
  1109.  
  1110. void RepairBase()
  1111. {
  1112.     struct PortData *cport=(PortData *)FindTask(NULL)->tc_UserData;
  1113.     char buffer[256],quit=FALSE;
  1114.     List dirlist;
  1115.     BPTR index_mulder=NULL,
  1116.          data_mulder=NULL,
  1117.          mulder=NULL,
  1118.          lock=NULL,
  1119.          lock2=NULL,
  1120.          serial_mulder=NULL,
  1121.          serial_names=NULL;
  1122.     struct Subboard *subboard;
  1123.     struct ItemHeader *itemheader;
  1124.     struct Item *item;
  1125.     struct IndexEntry *indexentry;
  1126.     struct IndexEntry *indexentry2;
  1127.     struct IndexHeader indexheader;
  1128.     struct smulder *currentdir=0;
  1129.     struct smulder *newdir=0;
  1130.     struct DirectoryIndexHeader dih;
  1131.     struct DirIndexEntry        die;
  1132.     struct ItemIndexHeader        iih;
  1133.     struct ItemIndexEntry         iie;
  1134.     char Quit2=FALSE;
  1135.     char Quit=FALSE;
  1136.     ULONG dircounter=0;
  1137.  
  1138.     NewList(&dirlist);
  1139.     sprintf(buffer,"%sroot/",cport->sysdirs->sysdata);
  1140.  
  1141.     if (!(item=AllocVec(sizeof(Item),MEMF_ANY|MEMF_CLEAR)))Quit=TRUE;
  1142.     if (!(indexentry=AllocVec(sizeof(IndexEntry),MEMF_ANY)))Quit=TRUE;
  1143.  
  1144.     subboard=(Subboard *)item;
  1145.     itemheader=(ItemHeader *)item;
  1146.  
  1147.     if (!(lock=Lock(buffer,SHARED_LOCK)))
  1148.     {
  1149.         if (!(lock=CreateDir(buffer))) 
  1150.             Quit=TRUE;
  1151.         else
  1152.             ChangeMode(CHANGE_LOCK,lock,SHARED_LOCK);
  1153.     }
  1154.     if (lock)
  1155.     {
  1156.         if (NameFromLock(lock,buffer,255))
  1157.         {
  1158.             if (currentdir=AllocVec(sizeof(smulder),MEMF_ANY|MEMF_CLEAR))
  1159.             {
  1160.                 if (currentdir->ln_Name=AllocVec(strlen(buffer)+1,MEMF_ANY))
  1161.                 {
  1162.                     strcpy(currentdir->ln_Name,buffer);
  1163.                     AddTail(&dirlist,(Node *)currentdir);
  1164.                     sprintf(buffer,"%s/data/.index",currentdir->ln_Name);
  1165.                     if (!(index_mulder=Open(buffer,MODE_READWRITE)))
  1166.                     {
  1167.                         if (lock2=CreateDir(buffer))
  1168.                         {
  1169.                             UnLock(lock2);
  1170.                             if (!(index_mulder=Open(buffer,MODE_READWRITE)))
  1171.                             {
  1172.                                 Quit=TRUE;
  1173.                                 ioprintf("can't create root.index.\n");
  1174.                             }
  1175.                         }
  1176.                         else
  1177.                         {
  1178.                             ioprintf("can't create root/data directory.\n");
  1179.                             Quit=TRUE;
  1180.                         }
  1181.                     }
  1182.                     sprintf(buffer,"%ssys.dirtable.index",cport->sysdirs->sysdata);
  1183.                     if (serial_mulder=Open(buffer,MODE_READWRITE))
  1184.                     {
  1185.                         ClearMemQuick(&dih,sizeof(DirectoryIndexHeader));
  1186.                         Read(serial_mulder,&dih,sizeof(DirectoryIndexHeader));
  1187.                         Seek(serial_mulder,0,OFFSET_BEGINNING);
  1188.                         Write(serial_mulder,&dih,sizeof(DirectoryIndexHeader));
  1189.                     }
  1190.                     else
  1191.                         Quit=TRUE;
  1192.                     sprintf(buffer,"%ssys.dirtable.names",cport->sysdirs->sysdata);
  1193.                     if (serial_names=Open(buffer,MODE_READWRITE))
  1194.                         Seek(serial_names,0,OFFSET_END);
  1195.                     else
  1196.                         Quit=TRUE;
  1197.                 }
  1198.                 else
  1199.                 {
  1200.                     FreeVec(currentdir);
  1201.                     Quit=TRUE;
  1202.                 }
  1203.             }
  1204.         }
  1205.         UnLock(lock);
  1206.         if (index_mulder)
  1207.         {
  1208.             Seek(index_mulder,0,OFFSET_END);
  1209.             if (Seek(index_mulder,0,OFFSET_BEGINNING)>=sizeof(IndexHeader))
  1210.             {
  1211.                 Read(index_mulder,&indexheader,sizeof(IndexHeader));
  1212.             }
  1213.             else
  1214.             {
  1215.                 ClearMemQuick(&indexheader,sizeof(IndexHeader));
  1216.                 Write(index_mulder,&indexheader.Entrys,4);
  1217.                 ioprintf("index mulder is empty\n");
  1218.             }
  1219.             Close(index_mulder);
  1220.         }
  1221.         else
  1222.         {
  1223.             Quit=TRUE;
  1224.             ioprintf("can't open %s\n",buffer);
  1225.         }
  1226.         currentdir->index_mulder=0;
  1227.         currentdir->data_mulder=0;
  1228.     }
  1229.     while (!Quit && !cport->ProgramClose && cport->network.online)
  1230.     {
  1231.         ClearMemQuick(&indexheader,sizeof(IndexHeader));
  1232.         if (!currentdir->index_mulder)
  1233.         {
  1234.             sprintf(buffer,"%s/data/.index",currentdir->ln_Name);
  1235.             ioprintf("index open: %s\n",buffer);
  1236.             currentdir->index_mulder=Open(buffer,MODE_READWRITE);
  1237.         }
  1238.         if (currentdir->index_mulder)
  1239.         {
  1240.                 if (!currentdir->data_mulder)
  1241.                 {
  1242.                     Read(currentdir->index_mulder,&indexheader,sizeof(IndexHeader));
  1243.                     sprintf(buffer,"%s/data/.data",currentdir->ln_Name);
  1244.                     currentdir->data_mulder=Open(buffer,MODE_READWRITE);
  1245.                     ioprintf("data open: %s\n",buffer);
  1246.                 }
  1247.                 if (currentdir->data_mulder)
  1248.                 {
  1249.                     Quit2=FALSE;
  1250.                     while (!Quit2)
  1251.                     {
  1252.                         if (Read(currentdir->index_mulder,indexentry,sizeof(IndexEntry)))
  1253.                         {
  1254.                             if (Seek(currentdir->data_mulder,indexentry->offset,OFFSET_BEGINNING)>-1)
  1255.                             {
  1256.                                 if (indexentry->type==ITEMTYPE_SUBBOARD)
  1257.                                 {
  1258.                                     if (Read(currentdir->data_mulder,itemheader,sizeof(Subboard))==sizeof(Subboard))
  1259.                                     {
  1260.                                         UWORD len=strlen(currentdir->ln_Name)+1;
  1261.                                         Seek(serial_names,0,OFFSET_END);
  1262.                                         die.seek=Seek(serial_names,0,OFFSET_END);
  1263.                                         Write(serial_names,&len,sizeof(UWORD));
  1264.                                         Write(serial_names,currentdir->ln_Name,len);
  1265.  
  1266.                                         Seek(serial_mulder,0,OFFSET_END);
  1267.                                         
  1268.                                         die.IPNumber64=0;
  1269.                                         die.IPNumber=dih.counter+1;
  1270.                                         die.dataseek=indexentry->offset;
  1271.                                         die.checksum=die.IPNumber+die.IPNumber64+die.seek+die.dataseek;
  1272.                                         Write(serial_mulder,&die,sizeof(DirIndexEntry));
  1273.  
  1274.                                         dih.counter++;
  1275.                                         dih.entrys++;
  1276.  
  1277.                                         itemheader->IPNumber=die.IPNumber;
  1278.  
  1279.                                         Seek(currentdir->data_mulder,indexentry->offset,OFFSET_BEGINNING);
  1280.                                         Write(currentdir->data_mulder,itemheader,sizeof(Subboard));
  1281.                                                                                 
  1282.                                         ioprintf("dir: %s\n",itemheader->Title);
  1283.                                         if (newdir=AllocVec(sizeof(smulder),MEMF_ANY|MEMF_CLEAR))
  1284.                                         {
  1285.                                             if (newdir->ln_Name=AllocVec(strlen(itemheader->Path)+1,MEMF_ANY|MEMF_CLEAR))
  1286.                                             {
  1287.                                                 strcpy(newdir->ln_Name,itemheader->Path);
  1288.                                                 sprintf(buffer,"%s/data/.index",itemheader->Path);
  1289.                                                 if (mulder=Open(buffer,MODE_OLDFILE))
  1290.                                                 {
  1291.                                                     Close(mulder);
  1292.                                                     sprintf(buffer,"%s/data/.data",itemheader->Path);
  1293.                                                     if (mulder=Open(buffer,MODE_OLDFILE))
  1294.                                                     {
  1295.                                                         Close(mulder);
  1296.                                                         AddTail(&dirlist,(Node *)newdir);
  1297.                                                         currentdir=newdir;
  1298.                                                         Quit2=TRUE;
  1299.                                                     }
  1300.                                                 }
  1301.                                                 if (!Quit2)
  1302.                                                 {
  1303.                                                     ioprintf("error: %s\n",buffer);
  1304.                                                     FreeVec(newdir->ln_Name);
  1305.                                                     FreeVec(newdir);
  1306.                                                 }
  1307.                                             }
  1308.                                             else
  1309.                                             {
  1310.                                                 ioprintf("Can't change directory, out of memory\n");
  1311.                                                 FreeVec(newdir);
  1312.                                             }
  1313.                                         }
  1314.  
  1315.                                     }
  1316.                                 }
  1317.                                 else
  1318.                                 {
  1319.                                     if (Read(currentdir->data_mulder,itemheader,sizeof(Item))==sizeof(Item))
  1320.                                     {
  1321.                                         BPTR itemserial_mulder;
  1322.                                         sprintf(buffer,"%s/data/.item.serials",currentdir->ln_Name);
  1323.                                         if (itemserial_mulder=Open(buffer,MODE_READWRITE))
  1324.                                         {
  1325.                                             if (Read(itemserial_mulder,&iih,sizeof(ItemIndexHeader))<sizeof(ItemIndexHeader))
  1326.                                             {
  1327.                                                 ClearMemQuick(&iih,sizeof(ItemIndexHeader));
  1328.                                                 Seek(itemserial_mulder,0,OFFSET_BEGINNING);
  1329.                                                 Write(itemserial_mulder,&iih,sizeof(ItemIndexHeader));
  1330.                                             }
  1331.                                             Seek(itemserial_mulder,0,OFFSET_END);
  1332.                                             iie.IPNumber64=0;
  1333.                                             iie.IPNumber=iih.counter+1;
  1334.                                             iie.seek=indexentry->offset;
  1335.                                             iie.checksum=iie.IPNumber+iie.IPNumber64+iie.seek;
  1336.                                             iih.version=NOVIA_SUBBOARD_VER;
  1337.                                             iih.counter++;
  1338.                                             iih.entrys++;
  1339.                                             itemheader->IPNumber=iie.IPNumber;
  1340.                                             item->DirIP=die.IPNumber;
  1341.  
  1342.                                             Write(itemserial_mulder,&iie,sizeof(ItemIndexEntry));
  1343.                                             Seek(itemserial_mulder,0,OFFSET_BEGINNING);
  1344.                                             Write(itemserial_mulder,&iih,sizeof(ItemIndexHeader));
  1345.                                             Close(itemserial_mulder);
  1346.     
  1347.                                             Seek(currentdir->data_mulder,indexentry->offset,OFFSET_BEGINNING);
  1348.                                             Write(currentdir->data_mulder,itemheader,sizeof(Item));
  1349.     
  1350.                                         }
  1351.                                         else
  1352.                                             ioprintf("can't open %s\n",buffer);
  1353.                                         ioprintf("item: %s\n",itemheader->Title);
  1354.                                     }
  1355.                                 }
  1356.                             }
  1357.                         }
  1358.                         else
  1359.                         {
  1360.                             if (currentdir->ln_Pred->ln_Pred)
  1361.                             {
  1362.                                 newdir=currentdir;
  1363.                                 currentdir=currentdir->ln_Pred;
  1364.                                 Remove((Node *)newdir);
  1365.                                 if (newdir->ln_Name)FreeVec(newdir->ln_Name);
  1366.                                 if (newdir->index_mulder)Close(newdir->index_mulder);
  1367.                                 if (newdir->data_mulder)Close(newdir->data_mulder);
  1368.                                 FreeVec(newdir);
  1369.                                 ioprintf("Q2\n");
  1370.                             }
  1371.                             else
  1372.                             {
  1373.                                 if (dircounter==0)Quit=TRUE;
  1374.                                 Quit2=TRUE;
  1375.                             }
  1376.                         }
  1377.                     }
  1378.                 }
  1379.         }
  1380.         else
  1381.         {
  1382.             if (currentdir->ln_Pred->ln_Pred)
  1383.             {
  1384.                 newdir=currentdir;
  1385.                 currentdir=currentdir->ln_Pred;
  1386.                 Remove((Node *)newdir);
  1387.                 if (newdir->ln_Name)FreeVec(newdir->ln_Name);
  1388.                 if (newdir->index_mulder)Close(newdir->index_mulder);
  1389.                 if (newdir->data_mulder)Close(newdir->data_mulder);
  1390.                 FreeVec(newdir);
  1391.                 dircounter--;
  1392.                 ioprintf("Q4\n");
  1393.             }
  1394.             else
  1395.             {
  1396.                 ioprintf("E4\n");
  1397.                 Quit=TRUE;
  1398.             }
  1399.         }
  1400.  
  1401.         if (IsListEmpty(&dirlist))Quit=TRUE;
  1402.     }
  1403.     if (item)FreeVec(item);
  1404.     if (indexentry)FreeVec(indexentry);
  1405.     if (serial_mulder)
  1406.     {
  1407.         Seek(serial_mulder,0,OFFSET_BEGINNING);
  1408.         Write(serial_mulder,&dih,sizeof(DirectoryIndexHeader));
  1409.         Close(serial_mulder);
  1410.     }
  1411.     if (serial_names)
  1412.         Close(serial_names);
  1413.         
  1414. }
  1415.  
  1416.  
  1417. struct Subboard *GetSubboard_byIP(ULONG serialIP,struct Subboard *subboard,ULONG size)
  1418. {
  1419.     struct PortData *cport=(PortData *)FindTask(NULL)->tc_UserData;
  1420.     BPTR index_mulder,names_mulder;
  1421.     char buffer[256];
  1422.     struct Subboard *result=0;
  1423.     sprintf(buffer,"%ssys.dirtable.index",cport->sysdirs->sysdata);
  1424.     if (index_mulder=Open(buffer,MODE_OLDFILE))
  1425.     {
  1426.         sprintf(buffer,"%ssys.dirtable.names",cport->sysdirs->sysdata);
  1427.         if (names_mulder=Open(buffer,MODE_OLDFILE))
  1428.         {
  1429.             ULONG ulong;
  1430.             struct DirectoryIndexHeader *dih;
  1431.             struct DirIndexEntry  *die;
  1432.             char *names;
  1433.             BPTR mulder;
  1434.             char *pt;
  1435.             ULONG datasize;
  1436.             Seek(index_mulder,0,OFFSET_END);
  1437.             datasize=Seek(index_mulder,0,OFFSET_BEGINNING);
  1438.  
  1439.             Seek(names_mulder,0,OFFSET_END);
  1440.             ulong=Seek(names_mulder,0,OFFSET_BEGINNING);
  1441.  
  1442.             names=AllocVec(ulong,MEMF_ANY);
  1443.             Read(names_mulder,names,ulong);
  1444.             if (pt=AllocVec(datasize,MEMF_ANY))
  1445.             {
  1446.                 ULONG counter;
  1447.  
  1448.                 Read(index_mulder,pt,datasize);
  1449.  
  1450.                 dih=(DirectoryIndexHeader *)pt;
  1451.                 die=(DirIndexEntry *)&pt[sizeof(DirectoryIndexHeader)];
  1452.  
  1453.                 for (counter=0;((counter<dih->entrys) && (!(die[counter].IPNumber==serialIP)));counter++);
  1454.                 if (die[counter].IPNumber==serialIP)
  1455.                 {
  1456.                     sprintf(buffer,"%s/data/.data",&names[die[counter].seek+2]);
  1457.                     if (mulder=Open(buffer,MODE_OLDFILE))
  1458.                     {
  1459.                         if (Seek(mulder,die[counter].dataseek,OFFSET_BEGINNING)!=ENDSTREAMCH)
  1460.                             if (Read(mulder,subboard,size))
  1461.                                 result=subboard;
  1462.                         Close(mulder);
  1463.                     }
  1464.                 }
  1465.                 FreeVec(pt);
  1466.             }
  1467.             FreeVec(names);
  1468.             Close(names_mulder);
  1469.         }
  1470.         Close(index_mulder);
  1471.     }
  1472.     return result;
  1473. }
  1474.  
  1475. struct Item *GetItem_byIP(ULONG dirIP,ULONG itemIP,struct Item *item,ULONG size)
  1476. {
  1477.     struct PortData *cport=(PortData *)FindTask(NULL)->tc_UserData;
  1478.     BPTR index_mulder,names_mulder;
  1479.     char buffer[200];
  1480.     struct ItemHeader itemheader;
  1481.     struct Item *result=0;
  1482.     sprintf(buffer,"%ssys.dirtable.index",cport->sysdirs->sysdata);
  1483.     if (index_mulder=Open(buffer,MODE_OLDFILE))
  1484.     {
  1485.         sprintf(buffer,"%ssys.dirtable.names",cport->sysdirs->sysdata);
  1486.         if (names_mulder=Open(buffer,MODE_OLDFILE))
  1487.         {
  1488.             ULONG ulong;
  1489.             struct DirectoryIndexHeader *dih;
  1490.             struct DirIndexEntry  *die;
  1491.             char *names;
  1492.             BPTR mulder;
  1493.             char *pt;
  1494.             ULONG datasize;
  1495.             Seek(index_mulder,0,OFFSET_END);
  1496.             datasize=Seek(index_mulder,0,OFFSET_BEGINNING);
  1497.             Seek(names_mulder,0,OFFSET_END);
  1498.             ulong=Seek(names_mulder,0,OFFSET_BEGINNING);
  1499.             names=AllocVec(ulong,MEMF_ANY);
  1500.             Read(names_mulder,names,ulong);
  1501.             if (pt=AllocVec(datasize,MEMF_ANY))
  1502.             {
  1503.                 ULONG counter;
  1504.                 Read(index_mulder,pt,datasize);
  1505.                 dih=(DirectoryIndexHeader *)pt;
  1506.                 die=(DirIndexEntry *)&pt[sizeof(DirectoryIndexHeader)];
  1507.                 for (counter=0;((counter<dih->entrys) && (!(die[counter].IPNumber==dirIP)));counter++);
  1508.                 if (die[counter].IPNumber==dirIP)
  1509.                 {
  1510.                     sprintf(buffer,"%s/data/.data",&names[die[counter].seek+2]);
  1511.                     if (mulder=Open(buffer,MODE_OLDFILE))
  1512.                     {
  1513.                         if (Seek(mulder,die[counter].dataseek,OFFSET_BEGINNING)!=ENDSTREAMCH)
  1514.                         {
  1515.                             if (Read(mulder,&itemheader,sizeof(ItemHeader)))
  1516.                             {
  1517.                                 BPTR serial_mulder,item_mulder;
  1518.                                 sprintf(buffer,"%s/data/.item.serials",itemheader.Path);
  1519.                                 if (serial_mulder=Open(buffer,MODE_OLDFILE))
  1520.                                 {
  1521.                                     sprintf(buffer,"%s/data/.data",itemheader.Path);
  1522.                                     if (item_mulder=Open(buffer,MODE_OLDFILE))
  1523.                                     {
  1524.                                         char *pt2;
  1525.                                         Seek(serial_mulder,0,OFFSET_END);
  1526.                                         ulong=Seek(serial_mulder,0,OFFSET_BEGINNING);
  1527.                                         if (pt2=AllocVec(ulong,MEMF_ANY))
  1528.                                         {
  1529.                                             if (Read(serial_mulder,pt2,ulong)!=ENDSTREAMCH)
  1530.                                             {
  1531.                                                 ItemIndexHeader *iih=(ItemIndexHeader *)pt2;
  1532.                                                 ItemIndexEntry *iie=(ItemIndexEntry *)iih+1;
  1533.                                                 for (counter=0;((counter<iih->entrys) && (!(iie[counter].IPNumber==itemIP)));counter++);
  1534.                                                     if (iie[counter].IPNumber==itemIP)
  1535.                                                         if (Seek(item_mulder,iie[counter].seek,OFFSET_BEGINNING)!=ENDSTREAMCH)
  1536.                                                             if (Read(item_mulder,item,size))
  1537.                                                                 result=item;
  1538.                                                     
  1539.                                             }
  1540.                                             FreeVec(pt2);
  1541.                                         }    
  1542.                                         result=item;
  1543.                                         Close(item_mulder);
  1544.                                     }
  1545.                                     Close(serial_mulder);
  1546.                                 }
  1547.                             }
  1548.                         }
  1549.                         Close(mulder);
  1550.                     }
  1551.                 }
  1552.                 FreeVec(pt);
  1553.             }
  1554.             FreeVec(names);
  1555.             Close(names_mulder);
  1556.         }
  1557.         Close(index_mulder);
  1558.     }
  1559.     return result;
  1560. }
  1561.  
  1562.